#ifndef EVENT_HANDLER_H_2017_01_12
#define EVENT_HANDLER_H_2017_01_12
#include "ieventhandler.h"
#include "net.h"
#include "../eventmgr/ieventmgr.h"
class lobbyeventhandler :public ieventhandler
{
public:
	lobbyeventhandler(ilogicinterface* ioh, ieventmgr * mgr)
	{
		_currlen=0;
		_iohandler = ioh;
		_ieventmgr = mgr;
	}
public:
	bool init()
	{
		//
		return true;
	}
	bool start()
	{
		//
		return true;
	}
	void update()
	{
		//parse data
		if(_iohandler->get_len() >= 4)
		{
			_currlen = _iohandler->get_event_data(_buff,4);
			if(_currlen == 4)
			{
				unsigned int len = (unsigned int)(*_buff);
				if(len > 0 )
					_currlen += _iohandler->get_event_data(_buff+4,len);
			}
			
		}
		if(_currlen > 0)
		{
			Event* ev = new Event();
			ev->ParseFromArray(_buff+20,_currlen - 20);
			_ieventmgr->deal_with(ev,unsigned int(*(_buff +8)),unsigned int(*(_buff + 12)),unsigned int(*(_buff + 16)));
		}
		_currlen =0;
	}
};

class routereventhandler:public ieventhandler
{
public:
	routereventhandler(ilogicinterface* ioh)
	{
		_currlen=0;

		_iohandler = ioh;
	}
public:
	bool init()
	{

	}
	bool start()
	{

	}
	void update()
	{
		unsigned int max_len = _iohandler->get_len();
		max_len = max_len > MAX_CACHE_SIZE_SERVER ? MAX_CACHE_SIZE_SERVER :  max_len;
		unsigned int len = _iohandler->get_event_data(_buff,max_len);
		if(len > 0)
		{
			_iohandler->push_net_data(_buff,len);
		}

	}
};
#endif//EVENT_HANDLER_H_2017_01_12

